# load packages

pacman::p_load(tidyverse, fixest)

### table A.4 (perceived threat and hearing about crime in media) ----

# load data
pools <- read_rds("data/survey.rds")

# create threat variables
pools <- pools %>%
    rowwise() %>%
    mutate(pool_threat = mean(c(pool1_1,pool1_2,pool1_3,pool1_4,pool1_5,pool1_6,pool1_7,pool1_8,pool1_9,
                                pool1_10, na.rm = T)),
           pool_threat_foreigners = mean(c(pool1_7,pool1_8,pool1_9,pool1_10, na.rm = T)),
           pool_threat = 6-pool_threat,
           pool_threat_foreigners = 6-pool_threat_foreigners)

# run regressions
m1 <- feols(pool_threat ~ hear_about_pool_crime +
                as.numeric(age) + factor(male) + factor(education) + factor(family_status) +
                factor(religious) + factor(parents_born_in_ger), data = pools, cluster=~zip)

m2 <- feols(pool_threat_foreigners ~ hear_about_pool_crime +
                as.numeric(age) + factor(male) + factor(education) + factor(family_status) +
                factor(religious) + factor(parents_born_in_ger), data = pools, cluster=~zip)

summary(m1)
summary(m2)

# clean
rm(list = ls())